package cap.dao.impl;

import cap.bean.Admin;
import cap.dao.AdminDao;
import cap.db.DBPool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDaoImpl implements AdminDao {
	/**
	 *登录
	 */
	@Override
	public Admin login(String userName, String passWord) {
		Admin admin = null;
		Connection conn=null;
		ResultSet rs = null;
		PreparedStatement ps=null;
		try {
			String sql="select * from admin where username=? and password=?";
			conn=DBPool.getConn();
			ps=conn.prepareStatement(sql);
			ps.setString(1,userName);
			ps.setString(2,passWord);
			rs=ps.executeQuery();
			if (rs.next()) {
				admin = new Admin();
				admin.setId(rs.getInt("id"));
				admin.setUserName(rs.getString("username"));
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBPool.close(rs,ps,conn);
		}
		return admin;
	}

}
